package com.tkjt.pms.modules.kpinew.service;

import com.tkjt.pms.common.utils.DoubleUtil;
import com.tkjt.pms.modules.kpinew.mapper.KpiNewMapper;
import com.tkjt.pms.modules.kpinew.model.ViewConfig;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Transactional
@Service
public class KpiDataGetService {
    @Autowired
    private KpiNewMapper kpiNewMapper;
    /**
     * 柱状统计图（收入和EBITDA情况数据获取方法）
     * @param indexValueCodes
     * @param indexDepartGroup
     * @return
     */
    public Map<String,Object> getData11(Map<String,Object> data1, List<String> indexValueCodes, String departBiz, String indexYearMonth, String indexDepartGroup){

        String targetCode = indexValueCodes.get(0);
        String actualCode = indexValueCodes.get(1);
        Map<String,Object> param = new HashMap<>();
        param.put("departBiz",departBiz);
        if(StringUtils.isNotEmpty(indexDepartGroup)){
            param.put("indexDepartGroup",indexDepartGroup);
        }
        param.put("indexYearMonth","MC"+indexYearMonth);
        param.put("indexValueCode",targetCode);
        param.put("indexDepartGroups", ViewConfig.getIndexDepartGroups());
        //今年预算（万元）
        Map<String,Object> targeValue = kpiNewMapper.selectData11ForKpi(param);
        param.put("indexValueCode",actualCode);
        //今年实际（万元）
        Map<String,Object> actualValue = kpiNewMapper.selectData11ForKpi(param);
        int year = Integer.valueOf(indexYearMonth.substring(0,4));
        String month = indexYearMonth.substring(4);
        int lastYear = year - 1 ;
        param.put("indexYearMonth","MC"+lastYear+month);
        //去年实际（万元）
        Map<String,Object> lastYearActualValue = kpiNewMapper.selectData11ForKpi(param);
        //同比和达成率返回数据对象
        Map<String,Object> valueMap = new HashMap<>();
        valueMap.put("series1Title","今年预算");
        valueMap.put("series2Title","今年实际");
        valueMap.put("series3Title","去年实际");
        /*valueMap.put("minValue","0");
        valueMap.put("maxValue","8000");*/
        Map<String,Object> valueSeries1 = new LinkedHashMap<>();
        Map<String,Object> valueSeries2 = new LinkedHashMap<>();
        Map<String,Object> valueSeries3 = new LinkedHashMap<>();
        //预期值、实际值返回数据对象
        Map<String,Object> contrastsMap = new HashMap<>();
        contrastsMap.put("series1Title","达成率(%)");
        contrastsMap.put("series2Title","同比(%)");
        /*contrastsMap.put("minValue","-20");
        contrastsMap.put("maxValue","150");*/
        Map<String,Object> contrastsSeries1 = new LinkedHashMap<>();
        Map<String,Object> contrastsSeries2 = new LinkedHashMap<>();
        for(int i= 1 ; i <= 12 ; i++){
            if( i < 10){
                month = "0" + i ;
            }else{
                month = String.valueOf(i);
            }
            valueSeries1.put("m"+month,targeValue == null ? "0" : DoubleUtil.formateForDoubleScale0(Double.valueOf(targeValue.get("m"+month).toString())));
            valueSeries2.put("m"+month,actualValue == null ? "0" : DoubleUtil.formateForDoubleScale0(Double.valueOf(actualValue.get("m"+month).toString())));
            valueSeries3.put("m"+month,lastYearActualValue == null ? "0" : DoubleUtil.formateForDoubleScale0(Double.valueOf(lastYearActualValue.get("m"+month).toString())));
            contrastsSeries1.put("m"+month,(targeValue == null || actualValue == null) ? "0%" : DoubleUtil.formateForDoubleScale0(DoubleUtil.mul(DoubleUtil.div(Double.valueOf(actualValue.get("m"+month).toString()),Double.valueOf(targeValue.get("m"+month).toString())),100d))+"%");
            contrastsSeries2.put("m"+month,(lastYearActualValue == null || actualValue == null) ? "0%" : DoubleUtil.formateForDoubleScale0(DoubleUtil.mul(DoubleUtil.div(Double.valueOf(actualValue.get("m"+month).toString()),Double.valueOf(lastYearActualValue.get("m"+month).toString())),100d))+"%");
        }
        valueMap.put("series1",valueSeries1);
        valueMap.put("series2",valueSeries2);
        valueMap.put("series3",valueSeries3);
        contrastsMap.put("series1",contrastsSeries1);
        contrastsMap.put("series2",contrastsSeries2);
        data1.put("contrasts",contrastsMap);
        data1.put("value",valueMap);
        String[] xTitile = {"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};
        data1.put("xTitile",xTitile);
        return data1;
    }

    /**
     * 瀑布统计图
     * 各园区预算达成贡献度
     （收入、EBITDA和销售数据获取方法）
     * @param data2
     * @param indexValueCodes
     * @param indexYearMonth
     * @param indexDepartGroup
     * @return
     */
    public Map<String,Object> getdata12(Map<String,Object> data2,List<String> indexValueCodes,String departBiz,String indexYearMonth,String indexDepartGroup){
        String targetCode = indexValueCodes.get(0);
        String actualCode = indexValueCodes.get(1);
        Map<String,Object> param = new HashMap<>();
        param.put("departBiz",departBiz);
        if(StringUtils.isNotEmpty(indexDepartGroup)){
            param.put("indexDepartGroup",indexDepartGroup);
        }
        param.put("indexYearMonth","MC"+indexYearMonth);
        param.put("indexValueCode",targetCode);
        List<String> indexDepartGroups = ViewConfig.getIndexDepartGroups();
        Map<String,Object> valueMap = new HashMap<>();
        List<String> series1Titles = new ArrayList<>();
        series1Titles.add("汇总");
        series1Titles.add("燕");
        series1Titles.add("申");
        series1Titles.add("粤");
        series1Titles.add("蜀");
        series1Titles.add("吴");
        series1Titles.add("楚");
        series1Titles.add("大清谷");
        valueMap.put("series1Title",series1Titles);
        param.put("indexDepartGroups",indexDepartGroups);
        List<Double> targetList = kpiNewMapper.getData12ForKpi(param);
        param.put("indexValueCode",actualCode);
        List<Double> actualList = kpiNewMapper.getData12ForKpi(param);

        Double total = 0d;
        Double targetTotal = 0d;
        Double actualTotal = 0d;
        //实际值-目标值
        for(int i = 0 ; i < indexDepartGroups.size() ; i++){
            targetTotal = DoubleUtil.add(targetTotal,targetList.get(i));
            actualTotal = DoubleUtil.add(actualTotal,actualList.get(i));
            total = DoubleUtil.sub(actualTotal,targetTotal);
        }
        List<String> series1 = new ArrayList<>();
        List<String> series2 = new ArrayList<>();
        List<String> series3 = new ArrayList<>();
        series1.add("-");
        series2.add(DoubleUtil.formateForDoubleScale0(total));
        series3.add("-");
        for(int i = 0 ; i < indexDepartGroups.size() ; i++){
            Double seriesData = DoubleUtil.sub(actualList.get(i),targetList.get(i));
            series1.add("-");
            series2.add(DoubleUtil.formateForDoubleScale0(seriesData));
            series3.add("-");
            //tempTotal = makeFallsData3(tempTotal,seriesData,series1,series2,series3);
        }
        valueMap.put("series1",series1);
        valueMap.put("series2",series2);
        valueMap.put("series3",series3);
        data2.put("value",valueMap);
        return data2;
    }
    /**
     * 饼状图
     * 各园区收入占比（收入和销售数据获取方法）
     * @param data3
     * @param indexValueCodes
     * @param indexYearMonth
     * @param indexDepartGroup
     * @return
     */
    public Map<String,Object> getdata13(Map<String,Object> data3,List<String> indexValueCodes,String departBiz,String indexYearMonth,String indexDepartGroup){
        String actualCode = indexValueCodes.get(0);
        Map<String,Object> param = new HashMap<>();
        param.put("departBiz",departBiz);
        if(StringUtils.isNotEmpty(indexDepartGroup)){
            param.put("indexDepartGroup",indexDepartGroup);
        }
        param.put("indexYearMonth","MC"+indexYearMonth);
        List<String> indexDepartGroups = ViewConfig.getIndexDepartGroups();
        Map<String,Object> valueMap = new HashMap<>();
        List<String> series1Titles = new ArrayList<>();
        series1Titles.add("燕");
        series1Titles.add("申");
        series1Titles.add("粤");
        series1Titles.add("蜀");
        series1Titles.add("吴");
        series1Titles.add("楚");
        series1Titles.add("大清谷");
        valueMap.put("series1Title",series1Titles);
        param.put("indexDepartGroups",indexDepartGroups);
        param.put("indexValueCode",actualCode);
        List<Double> actualList = kpiNewMapper.getData12ForKpi(param);
        List<String> fianlList = new ArrayList<>();
        for(Double actual : actualList){
            fianlList.add(DoubleUtil.formateForDoubleScale0(actual));
        }
        valueMap.put("series1",fianlList);
        data3.put("value",valueMap);
        return data3;
    }


    /**
     * 饼状图
     * 业态收入占比（收入、EBITDA和销售数据获取方法）
     * @param data4
     * @param indexValueCodes
     * @param indexYearMonth
     * @param indexDepartGroup
     * @return
     */
    public Map<String,Object> getdata14(Map<String,Object> data4,List<String> indexValueCodes,String indexYearMonth,String indexDepartGroup){
        String actualCode = indexValueCodes.get(0);
        Map<String,Object> param = new HashMap<>();
        if(StringUtils.isNotEmpty(indexDepartGroup)){
            param.put("indexDepartGroup",indexDepartGroup);
        }
        param.put("indexYearMonth","MC"+indexYearMonth);
        param.put("indexValueCode",actualCode);
        List<String> indexDepartGroups = ViewConfig.getIndexDepartGroups();
        Map<String,Object> valueMap = new HashMap<>();
        List<String> series1Titles = new ArrayList<>();
        series1Titles.add("独立");
        series1Titles.add("护理");
        series1Titles.add("医院");
        valueMap.put("series1Title",series1Titles);
        param.put("indexDepartGroups",indexDepartGroups);
        List<Double> actualList = kpiNewMapper.getData14ForKpi(param);
        List<String> fianlList = new ArrayList<>();
        for(Double actual : actualList){
            fianlList.add(DoubleUtil.formateForDoubleScale0(actual));
        }
        valueMap.put("series1",fianlList);
        data4.put("value",valueMap);
        return data4;
    }

    /**
     * 柱状统计图（收入和EBITDA情况数据获取方法）
     * @param indexValueCodes
     * @param indexDepartGroup
     * @return
     */
    public Map<String,Object> getData21(Map<String,Object> data1, List<String> indexValueCodes, String departBiz, String indexYearMonth, String indexDepartGroup){

        String targetCode = indexValueCodes.get(0);
        String actualCode = indexValueCodes.get(1);
        Map<String,Object> param = new HashMap<>();
        param.put("departBiz",departBiz);
        if(StringUtils.isNotEmpty(indexDepartGroup)){
            param.put("indexDepartGroup",indexDepartGroup);
        }
        param.put("indexYearMonth","MC"+indexYearMonth);
        param.put("indexValueCode",targetCode);
        param.put("indexDepartGroups", ViewConfig.getIndexDepartGroups());
        //今年预算（万元）
        Map<String,Object> targeValue = kpiNewMapper.selectData11ForKpi(param);
        param.put("indexValueCode",actualCode);
        //今年实际（万元）
        Map<String,Object> actualValue = kpiNewMapper.selectData11ForKpi(param);
        int year = Integer.valueOf(indexYearMonth.substring(0,4));
        String month = indexYearMonth.substring(4);
        int lastYear = year - 1 ;
        param.put("indexYearMonth","MC"+lastYear+month);
        //去年实际（万元）
        Map<String,Object> lastYearActualValue = kpiNewMapper.selectData11ForKpi(param);
        //同比和达成率返回数据对象
        Map<String,Object> valueMap = new HashMap<>();
        valueMap.put("series1Title","今年预算");
        valueMap.put("series2Title","今年实际");
        valueMap.put("series3Title","去年实际");
        /*valueMap.put("minValue","-3000");
        valueMap.put("maxValue","200");*/
        Map<String,Object> valueSeries1 = new LinkedHashMap<>();
        Map<String,Object> valueSeries2 = new LinkedHashMap<>();
        Map<String,Object> valueSeries3 = new LinkedHashMap<>();
        //预期值、实际值返回数据对象
        Map<String,Object> contrastsMap = new HashMap<>();
        contrastsMap.put("series1Title","达成率(%)");
        contrastsMap.put("series2Title","同比(%)");
        /*contrastsMap.put("minValue","-20");
        contrastsMap.put("maxValue","150");*/
        Map<String,Object> contrastsSeries1 = new LinkedHashMap<>();
        Map<String,Object> contrastsSeries2 = new LinkedHashMap<>();
        for(int i= 1 ; i <= 12 ; i++){
            if( i < 10){
                month = "0" + i ;
            }else{
                month = String.valueOf(i);
            }
            valueSeries1.put("m"+month,targeValue == null ? "0" : DoubleUtil.formateForDoubleScale0(Double.valueOf(targeValue.get("m"+month).toString())));
            valueSeries2.put("m"+month,actualValue == null ? "0" : DoubleUtil.formateForDoubleScale0(Double.valueOf(actualValue.get("m"+month).toString())));
            valueSeries3.put("m"+month,lastYearActualValue == null ? "0" : DoubleUtil.formateForDoubleScale0(Double.valueOf(lastYearActualValue.get("m"+month).toString())));
            contrastsSeries1.put("m"+month,(targeValue == null || actualValue == null) ? "0%" : DoubleUtil.formateForDoubleScale0(DoubleUtil.mul(DoubleUtil.div(Double.valueOf(actualValue.get("m"+month).toString()),Double.valueOf(targeValue.get("m"+month).toString())),100d))+"%");
            contrastsSeries2.put("m"+month,(lastYearActualValue == null || actualValue == null) ? "0%" : DoubleUtil.formateForDoubleScale0(DoubleUtil.mul(DoubleUtil.div(Double.valueOf(actualValue.get("m"+month).toString()),Double.valueOf(lastYearActualValue.get("m"+month).toString())),100d))+"%");
        }
        valueMap.put("series1",valueSeries1);
        valueMap.put("series2",valueSeries2);
        valueMap.put("series3",valueSeries3);
        contrastsMap.put("series1",contrastsSeries1);
        contrastsMap.put("series2",contrastsSeries2);
        data1.put("contrasts",contrastsMap);
        data1.put("value",valueMap);
        String[] xTitile = {"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};
        data1.put("xTitile",xTitile);
        return data1;
    }

    /**
     * 瀑布统计图
     * 各园区收入占比（EBITDA数据获取方法）
     * @param indexValueCodes
     * @param indexYearMonth
     * @param indexDepartGroup
     * @return
     */
    public Map<String,Object> getdata23(Map<String,Object> data3,List<String> indexValueCodes,String departBiz,String indexYearMonth,String indexDepartGroup){
        String actualCode = indexValueCodes.get(0);
        Map<String,Object> param = new HashMap<>();
        param.put("departBiz",departBiz);
        if(StringUtils.isNotEmpty(indexDepartGroup)){
            param.put("indexDepartGroup",indexDepartGroup);
        }
        param.put("indexYearMonth","MC"+indexYearMonth);
        param.put("indexValueCode",actualCode);
        List<String> indexDepartGroups = ViewConfig.getIndexDepartGroups();
        Map<String,Object> valueMap = new HashMap<>();
        List<String> series1Titles = new ArrayList<>();
        series1Titles.add("汇总");
        series1Titles.add("燕");
        series1Titles.add("申");
        series1Titles.add("粤");
        series1Titles.add("蜀");
        series1Titles.add("吴");
        series1Titles.add("楚");
        series1Titles.add("大清谷");
        valueMap.put("series1Title",series1Titles);
        param.put("indexDepartGroups",indexDepartGroups);
        List<Double> actualList = kpiNewMapper.getData12ForKpi(param);
        Double total = 0d;
        //实际值-目标值
        for(int i = 0 ; i < indexDepartGroups.size() ; i++){
            total = DoubleUtil.add(total,actualList.get(i));
        }
        List<String> series1 = new ArrayList<>();
        List<String> series2 = new ArrayList<>();
        List<String> series3 = new ArrayList<>();
        series1.add("-");
        series2.add(DoubleUtil.formateForDoubleScale0(total));
        series3.add("-");
        for(int i = 0 ; i < indexDepartGroups.size() ; i++){
            Double seriesData = actualList.get(i);
            series1.add("-");
            series2.add(DoubleUtil.formateForDoubleScale0(seriesData));
            series3.add("-");
            //tempTotal = makeFallsData3(tempTotal,seriesData,series1,series2,series3);
        }
        valueMap.put("series1",series1);
        valueMap.put("series2",series2);
        valueMap.put("series3",series3);
        data3.put("value",valueMap);
        return data3;
    }

    /**
     * 瀑布统计图
     *业态收入占比
     （收入、EBITDA和销售数据获取方法）
     * @param data4
     * @param indexValueCodes
     * @param indexYearMonth
     * @param indexDepartGroup
     * @return
     */
    public Map<String,Object> getdata24(Map<String,Object> data4,List<String> indexValueCodes,String indexYearMonth,String indexDepartGroup){
        String actualCode = indexValueCodes.get(0);
        Map<String,Object> param = new HashMap<>();
        if(StringUtils.isNotEmpty(indexDepartGroup)){
            param.put("indexDepartGroup",indexDepartGroup);
        }
        param.put("indexYearMonth","MC"+indexYearMonth);
        param.put("indexValueCode",actualCode);
        Map<String,Object> valueMap = new HashMap<>();
        List<String> series1Titles = new ArrayList<>();
        series1Titles.add("汇总");
        series1Titles.add("独立");
        series1Titles.add("护理");
        series1Titles.add("医院");
        valueMap.put("series1Title",series1Titles);
        List<String> indexDepartGroups = ViewConfig.getIndexDepartGroups();
        param.put("indexDepartGroups",indexDepartGroups);
        List<Double> actualList = kpiNewMapper.getData14ForKpi(param);
        List<String> series1 = new ArrayList<>();
        List<String> series2 = new ArrayList<>();
        List<String> series3 = new ArrayList<>();
        Double total = 0d;
        for(Double actual : actualList){
            total = DoubleUtil.add(total,actual);
        }
        series1.add("-");
        series2.add(DoubleUtil.formateForDoubleScale0(total));
        series3.add("-");
        for(int i = 0 ; i < series1Titles.size()-1 ; i++){
            Double seriesData = actualList.get(i);
            series1.add("-");
            series2.add(DoubleUtil.formateForDoubleScale0(seriesData));
            series3.add("-");
            //tempTotal = makeFallsData3(tempTotal,seriesData,series1,series2,series3);
        }
        valueMap.put("series1",series1);
        valueMap.put("series2",series2);
        valueMap.put("series3",series3);
        data4.put("value",valueMap);
        return data4;
    }

    /**
     * 柱状统计图（销售情况数据获取方法）
     * @param indexValueCodes
     * @param indexDepartGroup
     * @return
     */
    public Map<String,Object> getData31(Map<String,Object> data1,List<String> indexValueCodes,String departBiz,String indexYearMonth,String indexDepartGroup){
        Map<String,Object> param = new HashMap<>();
        param.put("departBiz",departBiz);
        if(StringUtils.isNotEmpty(indexDepartGroup)){
            String basicDepartCode = ViewConfig.getBasicDepartCodeByDepartGroup(indexDepartGroup);
            param.put("basicDepartCode",basicDepartCode);
        }
        Map<String,Object> valueSeries1 = new LinkedHashMap<>();
        Map<String,Object> valueSeries2 = new LinkedHashMap<>();
        String targetCode = indexValueCodes.get(0);
        String actualCode = indexValueCodes.get(1);
        if(StringUtils.isNotEmpty(indexDepartGroup)){
            param.put("indexDepartGroup",indexDepartGroup);
        }
        param.put("indexYearMonth","MC"+indexYearMonth);
        param.put("indexValueCode",targetCode);
        List<String> indexDepartGroups = ViewConfig.getIndexDepartGroups();
        param.put("indexDepartGroups",indexDepartGroups);
        Map<String,Object> contrastsSeries1 = kpiNewMapper.selectData11ForKpi(param);
        if(contrastsSeries1 == null){
            contrastsSeries1 = new HashMap<>();
        }
        param.put("indexValueCode",actualCode);
        Map<String,Object> contrastsSeries2 = kpiNewMapper.selectData11ForKpi(param);
        if(contrastsSeries2 == null){
            contrastsSeries2 = new HashMap<>();
        }
        String year = indexYearMonth.substring(0,4);

        //同比和达成率返回数据对象
        Map<String,Object> valueMap = new HashMap<>();
        valueMap.put("series2Title","退住");
        valueMap.put("series1Title","新增入住");
        /*valueMap.put("minValue","-2000");
        valueMap.put("maxValue","2000");*/
        //预期值、实际值返回数据对象
        Map<String,Object> contrastsMap = new HashMap<>();
        contrastsMap.put("series1Title","净新增目标值");
        contrastsMap.put("series2Title","净新增实际值");
       /* contrastsMap.put("minValue","-20");
        contrastsMap.put("maxValue","150");*/
        String minMonth = "";
        String maxMonth = "";
        for(int i= 1 ; i <= 12 ; i++) {
            int temp = i+1;
            minMonth = i < 10 ? "0" + i : String.valueOf(i);
            maxMonth = temp < 10 ? "0" + temp : String.valueOf(temp);
            param.put("maxYearMonthDay",year+maxMonth+"01");
            param.put("minYearMonthDay",year+minMonth+"01");
            Map<String,Object> value = kpiNewMapper.getData31ForKpi(param);
            valueSeries2.put("m" + minMonth, value != null ? DoubleUtil.formateForDoubleScale0(Double.valueOf(value.get("value2") != null ? "-"+value.get("value2").toString() : "0")) : 0);
            valueSeries1.put("m" + minMonth, value != null ? DoubleUtil.formateForDoubleScale0(Double.valueOf(value.get("value1") != null ? value.get("value1").toString() : "0")) : 0);

            contrastsSeries1.put("m"+minMonth,DoubleUtil.formateForDoubleScale0(Double.valueOf(contrastsSeries1.get("m"+minMonth) != null ? contrastsSeries1.get("m"+minMonth).toString() : "0"))+"%");
            contrastsSeries2.put("m"+minMonth,DoubleUtil.formateForDoubleScale0(Double.valueOf(contrastsSeries2.get("m"+minMonth) != null ? contrastsSeries2.get("m"+minMonth).toString() : "0"))+"%");
        }
        valueMap.put("series2",valueSeries2);
        valueMap.put("series1",valueSeries1);
        contrastsMap.put("series1",contrastsSeries1);
        contrastsMap.put("series2",contrastsSeries2);
        data1.put("contrasts",contrastsMap);
        data1.put("value",valueMap);
        String[] xTitile = {"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};
        data1.put("xTitile",xTitile);
        return data1;
    }

    /**
     * 柱状统计图（各园区床位使用率）
     * @param indexValueCodes
     * @param indexDepartGroup
     * @return
     */
    public Map<String,Object> getData32(Map<String,Object> data1, List<String> indexValueCodes, String departBiz, String indexYearMonth, String indexDepartGroup){

        String targetCode = indexValueCodes.get(0);
        String actualCode = indexValueCodes.get(1);
        Map<String,Object> param = new HashMap<>();
        param.put("departBiz",departBiz);
        if(StringUtils.isNotEmpty(indexDepartGroup)){
            param.put("indexDepartGroup",indexDepartGroup);
        }
        param.put("indexYearMonth","MC"+indexYearMonth);
        param.put("indexValueCode",targetCode);
        List<String> indexDepartGroups = ViewConfig.getIndexDepartGroups();
        param.put("indexDepartGroups", indexDepartGroups);
        //今年预算（万元）
        List<Double> targeValues = kpiNewMapper.getData32ForKpi(param);
        param.put("indexValueCode",actualCode);
        //今年实际（万元）
        List<Double> actualValues = kpiNewMapper.getData32ForKpi(param);
        int year = Integer.valueOf(indexYearMonth.substring(0,4));
        String month = indexYearMonth.substring(4);
        int lastYear = year - 1 ;
        param.put("indexYearMonth","MC"+lastYear+month);
        //去年实际（万元）
        List<Double> lastYearActualValues = kpiNewMapper.getData32ForKpi(param);
        //同比和达成率返回数据对象
        Map<String,Object> valueMap = new HashMap<>();
        valueMap.put("series1Title","今年预算");
        valueMap.put("series2Title","今年实际");
        valueMap.put("series3Title","去年实际");
        /*valueMap.put("minValue","0");
        valueMap.put("maxValue","8000");*/
        Map<String,Object> valueSeries1 = new LinkedHashMap<>();
        Map<String,Object> valueSeries2 = new LinkedHashMap<>();
        Map<String,Object> valueSeries3 = new LinkedHashMap<>();
        //预期值、实际值返回数据对象
        Map<String,Object> contrastsMap = new HashMap<>();
        contrastsMap.put("series1Title","达成率(%)");
        contrastsMap.put("series2Title","同比(%)");
       /* contrastsMap.put("minValue","-20");
        contrastsMap.put("maxValue","150");*/
        Map<String,Object> contrastsSeries1 = new LinkedHashMap<>();
        Map<String,Object> contrastsSeries2 = new LinkedHashMap<>();
        for(int i = 0 ; i < indexDepartGroups.size() ; i++){
            valueSeries1.put(indexDepartGroups.get(i), DoubleUtil.formateForDoubleScale0(targeValues.get(i)));
            valueSeries2.put(indexDepartGroups.get(i), DoubleUtil.formateForDoubleScale0(actualValues.get(i)));
            valueSeries3.put(indexDepartGroups.get(i),lastYearActualValues.size() == 0 ? "0" : DoubleUtil.formateForDoubleScale0(lastYearActualValues.get(i)));
            contrastsSeries1.put(indexDepartGroups.get(i),targeValues.get(i) == 0 ? "0%" : DoubleUtil.formateForDoubleScale0(DoubleUtil.mul(DoubleUtil.div(actualValues.get(i),targeValues.get(i)),100d))+"%");
            contrastsSeries2.put(indexDepartGroups.get(i),lastYearActualValues.size() == 0 || lastYearActualValues.get(i) == 0 ? "0%" : DoubleUtil.formateForDoubleScale0(DoubleUtil.mul(DoubleUtil.div(actualValues.get(i),lastYearActualValues.get(i)),100d))+"%");
        }
        valueMap.put("series1",valueSeries1);
        valueMap.put("series2",valueSeries2);
        valueMap.put("series3",valueSeries3);
        contrastsMap.put("series1",contrastsSeries1);
        contrastsMap.put("series2",contrastsSeries2);
        data1.put("contrasts",contrastsMap);
        data1.put("value",valueMap);
        String[] xTitile = {"燕园","申园","粤园","蜀园","吴园","楚园","大清谷"};
        data1.put("xTitile",xTitile);
        return data1;
    }

    /**
     * 饼状图
     * 业态收入占比 销售数据获取方法）
     * @param data4
     * @param indexValueCodes
     * @param indexYearMonth
     * @param indexDepartGroup
     * @return
     */
    public Map<String,Object> getdata34(Map<String,Object> data4,List<String> indexValueCodes,String indexYearMonth,String indexDepartGroup){
        String actualCode = indexValueCodes.get(0);
        Map<String,Object> param = new HashMap<>();
        if(StringUtils.isNotEmpty(indexDepartGroup)){
            param.put("indexDepartGroup",indexDepartGroup);
        }
        param.put("indexYearMonth","MC"+indexYearMonth);
        param.put("indexValueCode",actualCode);
        Map<String,Object> valueMap = new HashMap<>();
        List<String> series1Titles = new ArrayList<>();
        series1Titles.add("汇总");
        series1Titles.add("独立");
        series1Titles.add("护理");
        valueMap.put("series1Title",series1Titles);
        List<String> indexDepartGroups = ViewConfig.getIndexDepartGroups();
        param.put("indexDepartGroups",indexDepartGroups);
        List<Double> actualList = kpiNewMapper.getData14ForKpi(param);
        List<String> series1 = new ArrayList<>();
        List<String> series2 = new ArrayList<>();
        List<String> series3 = new ArrayList<>();
        Double total = 0d;
        for(int i = 0 ; i < actualList.size()-1 ; i++){
            total = DoubleUtil.add(total,actualList.get(i));
        }
        series1.add("-");
        series2.add(DoubleUtil.formateForDoubleScale0(total));
        series3.add("-");
        for(int i = 0 ; i < series1Titles.size()-1 ; i++){
            Double seriesData = actualList.get(i);
            series1.add("-");
            series2.add(DoubleUtil.formateForDoubleScale0(seriesData));
            series3.add("-");
        }
        valueMap.put("series1",series1);
        valueMap.put("series2",series2);
        valueMap.put("series3",series3);
        data4.put("value",valueMap);
        return data4;
    }

    /**
     * 瀑布统计图(阶梯三个集合)返回格式逻辑拼装
     * @param total
     * @param seriesData
     * @param series1
     * @param series2
     * @param series3
     */
    public Double makeFallsData3(Double total,Double seriesData,List<String> series1,List<String> series2,List<String> series3){
        if(seriesData >= 0){
            if(total > 0){
                if(series3.get(series3.size()-1).toString().equals("-")){
                    total = DoubleUtil.sub(total,seriesData);
                }else{
                    total = DoubleUtil.sub(DoubleUtil.add(total,Double.valueOf(series3.get(series3.size()-1).toString())),seriesData);

                }
                if(total < 0){
                    total = 0d;
                }
            }
            series1.add(DoubleUtil.formateForDoubleScale0(total));
            series2.add(DoubleUtil.formateForDoubleScale0(seriesData));
            series3.add("-");
        }else{
            series1.add(DoubleUtil.formateForDoubleScale0(total));
            series2.add("-");
            series3.add(DoubleUtil.formateForDoubleScale0(DoubleUtil.mul(seriesData,-1d)));
        }
        return total;
    }
}
